#include <dao.h>
#include <btBulletDynamicsCommon.h>

#include "btTransform.h"
#include "btVector3.h"

static void construct(DaoContext *ctx, DValue *p[], int N) {
    btQuaternion	*q = (btQuaternion*) DaoCData_GetData(p[0]->v.cdata);
    btVector3		*v = (btVector3*) DaoCData_GetData(p[1]->v.cdata);
    btTransform		*ptr = new btTransform(*q, *v);

    DaoCData *cdata = DaoContext_PutCData(ctx, ptr, &btTransformTyper);
};

static void construct2(DaoContext *ctx, DValue *p[], int N) {
    btTransform		*ptr = new btTransform();

    DaoCData *cdata = DaoContext_PutCData(ctx, ptr, &btTransformTyper);
};

static void destruct(void *self) {
    delete (btTransform*) self;
}

static void getOrigin(DaoContext *ctx, DValue *p[], int N) {
    btTransform		*ptr = (btTransform*) DaoCData_GetData(p[0]->v.cdata);
    btVector3		origin = ptr->getOrigin();
    btVector3		*res = new btVector3(origin);

    DaoContext_PutCData(ctx, res, &btVector3Typer);
}

static DaoFuncItem meth[] = {
    { construct,	"btTransform(q:btQuaternion, v:btVector3)" },
    { construct2,	"btTransform()" },

    { getOrigin,	"getOrigin(self:btTransform) => btVector3" },
    { NULL, NULL }
};

DaoTypeBase btTransformTyper = {
    "btTransform",
    NULL,
    NULL,               /* constant */
    meth,       	/* methods */
    { NULL },     	/* parent type */
    { NULL },
    destruct,
    NULL
};
